﻿using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class bs_inventory_alertsService : bs_inventory_alertsIService
    {
        private readonly MyDbContext MyDbContext;
        public bs_inventory_alertsService(MyDbContext myDb)
        {
            this.MyDbContext = myDb;
        }

        //添加
        public async Task<int> Add(bs_Inventory_Alerts bsAlerts)
        {
            await MyDbContext.bs_Inventory_Alerts.AddAsync(bsAlerts);
            return await MyDbContext.SaveChangesAsync();
        }

        //删除
        public async Task<int> Delete(int ia_id)
        {
            var del = MyDbContext.bs_Inventory_Alerts.Find(ia_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        //查询物品
        public async Task<List<bs_dict_image>> Query()
        {
            return await MyDbContext.bs_dict_image
                .Where(w => w.IsDeleted == false)
                .ToListAsync();
        }
        //查询字典--单位
        public async Task<List<bs_dict_data>> DictQuery()
        {
            return await MyDbContext.bs_dict_data
               .Where(w => w.IsDeleted == false)
               .ToListAsync();
        }

        //修改
        public async Task<int> Update(bs_Inventory_Alerts bsAlerts)
        {
            MyDbContext.bs_Inventory_Alerts.Update(bsAlerts);
            return await MyDbContext.SaveChangesAsync();
        }

        //查询系统库存
        public async Task<List<inv_goods_inventory>> InventoryQuery()
        {
            return await MyDbContext.inv_goods_inventory .ToListAsync();
        }
    }
}
